package com.work.demo.test;

/**
 * 全局错误码枚举
 * 一般情况下，使用 HTTP 响应状态码 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status
 *
 * @author admin
 */
public enum GlobalError implements BaseError {

    // ========== filter中的错误 ==========
    HEADER_NODE_ID_ERROR(40007, "Header中[X-Node-Id]请输入正确的值"),
    HEADER_TIMESTAMP_ERROR(40008, "Header中[X-Timestamp]请输入正确的值"),
    HEADER_EMPTY(40009, "Header中[%s]不能为空"),
    INVALID_PUBLIC_KEY(40010, "公钥校验失败, 请联系访问节点修正公钥"),
    INVALID_SIGN(40011, "无效X-Auth-Sign"),
    HEADER_ERROR(40012, "解析请求头出现异常"),
    NOT_PARTNERS(40013, "还未成为合作伙伴，无法访问！"),
    SIGN_ERROR(40014, "请求签名失败！"),
    SIGN_ALGO_ERROR(40015, "不支持的签名加密方式"),
    TOKEN_CHECK_FAIL(40016,"Token校验失败"),

    // ========== 客户端错误段 ==========
    BAD_REQUEST(400, "请求参数不正确"),
    UNAUTHORIZED(401, "账号未登录"),
    FORBIDDEN(403, "没有该操作权限"),
    NOT_FOUND(404, "请求未找到"),
    METHOD_NOT_ALLOWED(405, "请求方法不正确"),
    PARAM_TOO_LONG(406, "请求参数长度过长"),
    LOCKED(423, "请求失败，请稍后重试"),
    TOO_MANY_REQUESTS(429, "请求过于频繁，请稍后重试"),

    // ========== 服务端错误段 ==========
    INTERNAL_SERVER_ERROR(500, "系统异常"),
    OPTIMISTIC_LOCKING_FAILURE_EXCEPTION(501, "乐观锁异常"),

    // ========== Auth服务错误 ==========
    AUTH_SERVER_ERROR(600, "Auth服务调用异常"),

    //========== 自定义错误段 ==========
    REPEATED_REQUESTS(900, "重复请求，请稍后重试"),
    UNKNOWN(999, "未知错误"),
    NO_SIGNATURE(9902, "该请求无签名信息"),
    NO_TIMESTAMP(9903, "该请求无时间信息"),
    NO_REQUESTID(9904, "该请求无请求ID"),
    NO_TOKEN(9905, "该请求无Token信息"),
    REQUEST_OVERTIME(9906, "请求超时"),
    MESSAGE_TAMPERING(9907, "请求报文被篡改"),
    MESSAGE_REPLAY(9908, "重复请求"),
    REPEAT_LOGIN(9909, "登录超时或者该账号已在异地登录，请重新登录"),
    REPEAT_PASSWORD(9910, "新密码不能与最近三次修改的密码相同"),
    INCOMPLETE_PASSWORD(9911, "原始密码已被破坏，请联系管理员"),
    ILLEGAL_IP(9912, "客户端IP不合法，请检查登录IP"),
    SESSION_TIMEOUT(9913, "登录会话超时，请重新登录"),
    SPECIAL_CHARACTERS(9914, "有特殊字符输入，请检查输入文本"),


    //禁止sql注入
    prohibit_sql_injection(9915, "禁止SQL注入"),
    NO_ACCESS(9916, "禁止越权访问"),
    ;

    private final Integer code;
    private final String msg;

    GlobalError(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }
}